class Users {
  async index(req, res) {
    let result = await req.db.query('select `id`,`username`,`age` from `users`')
    res.send(result[0])
  }
  async find(req, res) {
    let { id } = req.query;
    let sql = 'select `id`,`username`,`age` from `users` where `id`=?'
    let result = await req.db.query(sql, [id])
    res.send(result[0][0])
  }
  async add(req, res) {
    let { username, age } = req.body,
      sql = 'insert into `users` set `username`=?,`age`=?';
    let result = await req.db.query(sql, [username, age])
    res.send(result[0])
  }

  async edit(req, res) {
    let { id, username, age } = req.body,
      sql = 'update `users` set `username`=?,`age`=? where `id`=?';
    let result = await req.db.query(sql, [username, age, id])
    res.send(result[0])
  }

  async del(req, res) {
    let { id } = req.query,
      sql = 'delete from `users` where `id`=?';
    let result = await req.db.query(sql, [id])
    res.send(result[0])
  }

}

module.exports = new Users();